package com.owc.common.sdk.request;

import com.owc.common.sdk.AbstractRequest;
import com.owc.common.sdk.response.WithdrawResponse;
import com.owc.domain.WithdrawBaseInfo;
import com.owc.domain.entity.WithdrawFlow;
import lombok.Data;
import org.apache.http.entity.ContentType;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 添加提币请求并返回提款用热钱包地址
 */
@Data
public class WithdrawRequest extends AbstractRequest implements Request<WithdrawResponse> {

    private List<WithdrawFlow> datas = new ArrayList<>();

    private String tokenName;

    private String chain;

    private String txnType;

    private String fromAddress;

    @Override
    protected void setUrlParamsMap(Map<String, Object> map) {
        List<Map<String,String>> requestList = new ArrayList<>();

        if(!datas.isEmpty()){
            for (WithdrawFlow data : datas) {
                Map<String,String> requestMap = new HashMap<>();
                requestMap.put("address",data.getWalletAddress());
                requestMap.put("amount",data.getRealAmount().toPlainString());
                requestMap.put("trace",data.getTransferId());
                requestMap.put("fromAddress",data.getFromAddress() == null ? fromAddress : data.getFromAddress());
                requestList.add(requestMap);
            }
        }
        map.put("request", requestList);
        map.put("tokenName",tokenName);
        map.put("chain",chain);
        map.put("txnType",txnType);
        map.put("fromAddress",fromAddress);
    }

    @Override
    public String getApiUrl() {
        return super.getBaseUrl() + "/wallet/withdraw";
    }

    @Override
    public Class<WithdrawResponse> getResponseClass() {
        return WithdrawResponse.class;
    }

    @Override
    public Object getUrlParams() {
        setUrlParamsMap(super.urlParamsMap);
        return super.urlParamsMap;
    }

    @Override
    public ContentType getContentType() {
        return ContentType.create(ContentType.APPLICATION_JSON.getMimeType(),"UTF-8");
    }
}
